package homework04;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;

public class Test {
    public static void main(String[] args) {
        Student stu = new Student("小猪", 20, "男");
        Student stu1 = new Student("佩奇", 22, "女");
        Student stu2 = new Student("阿门", 25, "男");
        ArrayList<Student> list = new ArrayList<>();
        list.add(stu);
        list.add(stu1);
        list.add(stu2);
        list.sort(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge()-o2.getAge();
            }
        });
        list.get(2).setName("小猪佩奇");
        Iterator<Student> iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }
    }
}
